package com.xiaodeng.xdblogspringboot.controller;

import cn.hutool.core.bean.BeanUtil;
import com.xiaodeng.xdblogspringboot.interceptors.AdminInterceptor;
import com.xiaodeng.xdblogspringboot.interceptors.LoginInterceptor;
import com.xiaodeng.xdblogspringboot.pojo.Application;
import com.xiaodeng.xdblogspringboot.pojo.DTO.ApplicationDTO;
import com.xiaodeng.xdblogspringboot.pojo.PageBean;
import com.xiaodeng.xdblogspringboot.pojo.Result;
import com.xiaodeng.xdblogspringboot.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/application")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    /**
     * 审计申请
     *
     * @param application 应用
     * @return result<应用程序>
     */
    @PutMapping("auditApplication")
    @AdminInterceptor.AdminIntercept
    public Result<Application> auditApplication(@RequestBody Application application) {
        applicationService.auditApplication(application);
        return Result.success();
    }

    /**
     * 管理员查询审核的申请记录（包含申请状态选择）
     *
     * @param pageNum     页码
     * @param pageSize    页面大小
     * @param title       标题
     * @param username    用户名
     * @param auditStatus 审核状态
     * @return 结果<页面 Bean < 应用程序 DTO>>
     */
    @GetMapping("getAllApplication")
    @AdminInterceptor.AdminIntercept
    public Result<PageBean<ApplicationDTO>> getAllApplication( Integer pageNum,
                                                            Integer pageSize,
                                                            @RequestParam(required = false) String title,
                                                            @RequestParam(required = false) String username,
                                                            @RequestParam(required = false) String auditStatus) {
        PageBean<ApplicationDTO> pb = applicationService.getAllApplication(pageNum,pageSize,title,username,auditStatus);
        return Result.success(pb);
    }

    /**
     * 用户查询申请审核进度
     *
     * @return result<list < application>>
     */
    @LoginInterceptor.GlobalJwtIntercept
    @GetMapping("getApplication")
    public Result<List<ApplicationDTO>> getApplication() {
        List<ApplicationDTO> list =  applicationService.getApplication();
        return Result.success(list);
    }



}
